<template>
	<div class="app-containers" v-if="userComanyId == 'null'||userComanyId == 0">
		<span class="label-titile">企业名称</span>
		<el-select 
			v-model="companyId" 
			placeholder="请选择"
			@change="changeCompany">
			<el-option 
				v-for="item in options" 
				:key="item.value" 
				:label="item.label" 
				:value="item.value"
				>
			</el-option>
		</el-select>
	</div>
</template>

<script>
	import { getComanyId, getComanySession, setComanySession } from '@/utils/auth'
	import { getCompany } from '@/utils/index'
	export default {
		name:"company",
		data() {
			return {
				userComanyId:"",
				companyId:"",
				options:[]
			}
		},
		created(){
			if(!getComanySession()){
				this.getCompany();	
			}else{
				let arry = JSON.parse(getComanySession());
				arry.forEach((item)=>{
					this.options.push({value: item.id,label: item.name})
				});
			}
			this.userComanyId = getComanyId();
		},
		methods:{
			getCompany(){
				getCompany().then((res)=>{
					setComanySession(JSON.stringify(res.entity));
					res.entity.forEach((item)=>{
						this.options.push({value: item.id,label: item.name})
					});
				})
			},
			changeCompany(value){
				this.$emit("choseCompany",value);
			}
			
		}
	}
</script>

<style>
</style>